<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/layui/css/layui.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/css/thesame.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/css/footer.css'" media="all"/>
		<link rel="stylesheet" type="text/css" th:href="${#request.getContextPath()}+'/static/foodDelivery/css/rightCon.css'" media="all"/>
		<style>
		</style>
	</head>

	<body class="layui-layout-body">
		<div class="layui-body">
			<div class="scroll-box scroll-box-bot bgWhite box-shadows border-radius4">
				<div class="new-add-box-width">
					<div class="add-mess add-mess-mb mar25px">
						<div class="add-mess-child">
							<div>
								<label><em class="red">*</em>每餐价格：</label>
							</div>
							<div class="add-mess-form">
								<p>
									<input id="mealsInput" th:value="${meal != null}?${meal.meals}:''" maxlength="10" type="text" placeholder="最多保留两位小数">
								</p>
							</div>
							<div class="ml10px">元</div>
						</div>
						<div class="add-mess-child">
							<div>
								<label><em class="red">*</em>送餐费/次：</label>
							</div>
							<div class="add-mess-form">
								<p><input id="deliveryFeeInput" th:value="${meal != null}?${meal.deliveryFee}:''" maxlength="10" type="text" placeholder="最多保留两位小数"></p>
							</div>
							<div class="ml10px">元</div>
						</div>
					</div>
				</div>
			</div>
			
		</div>
		<div class="layui-footer layui-footer-one">
			<div class="btn-con textCenter">
				<!--<span class="btn-one" id="cancelButton">取&nbsp;消</span>-->
				<span class="btn-two" id="submitButton" style="cursor: pointer">提&nbsp;交</span>
			</div>
		</div>
		<script th:src="${#request.getContextPath()}+'/static/js/jquery-2.1.3.min.js'"></script>
		<script th:src="${#request.getContextPath()}+'/static/layui/layui.js'"></script>
		<script>
			var saveFlag = true;
			layui.use(['jquery',"layer"], function() {
				var $ = layui.jquery;
				var layer = layui.layer;

				$("span#submitButton").on("click",function (e) {
					let meals = $("input#mealsInput").val();
					let deliveryFee = $("input#deliveryFeeInput").val();

					if(!meals){
						layer.msg("每餐价格不能为空！");
						$("input#mealsInput").focus();
						return false;
					}
					if(!/((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/.test(meals)){
						layer.msg("每餐价格格式不正确！");
						$("input#mealsInput").focus();
						return false;
					}
					if(!deliveryFee){
						layer.msg("送餐费不能为空！");
						$("input#deliveryFeeInput").focus();
						return false;
					}
					if(!/((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/.test(deliveryFee)){
						layer.msg("送餐费格式不正确！");
						$("input#deliveryFeeInput").focus();
						return false;
					}
					if(saveFlag){
						saveFlag = false;
						$.ajax({
							url:"../mealAllocation/save",
							type:"post",
							dataType:"json",
							data:{"meals":meals,"deliveryFee":deliveryFee},
							success:function (result) {
								saveFlag = true;
								layer.msg(result.msg);
							}
						})
					}
				})
			});
		</script>
	</body>

</html>
